<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page language="java" import="java.sql.*"%>

<%!public String getQuarter(int i) {
		String quarter;
		switch (i) {
		case 1:
			quarter = "Fall";
			break;

		case 2:
			quarter = "Winter";
			break;

		case 3:
			quarter = "Spring";
			break;

		case 4:
			quarter = "Summer";
			break;
		default:
			quarter = "ERROR";
		}

		return quarter;
	}%>
<%
	Class.forName("org.postgresql.Driver");
	Connection conn = DriverManager.getConnection(
			"jdbc:postgresql://localhost:5432/cse132b", "cse132blogin",
			"1234567890");
	Statement stmt;

	stmt = conn.createStatement();
	ResultSet rs = stmt
			.executeQuery("SELECT distinct classes.*, courses.course_number  FROM students , enroll, classes, courses WHERE students.student_id = enroll.student_id AND classes.class_id = enroll.section_id AND courses.course_id = classes.course_id ");

	String HTML = "";
	while (rs.next()) {

		HTML += "<tr>";
		HTML += "	<td><a href=report1bii.jsp?ID="
				+ rs.getInt("class_id") + ">" + rs.getString("course_number")
				+ "</a></td>";
		HTML += "	<td>" + rs.getString("class_id") + "</td>";
		HTML += "	<td>" + rs.getString("title") + "</td>";
		HTML += "	<td>" + getQuarter(Integer.valueOf(rs.getString("quarter"))) + "</td>";
		HTML += "	<td>" + rs.getString("year") + "</td>";
		HTML += "	<td>" + rs.getString("enrollment_limit") + "</td>";
	}
	rs.close();
	stmt.close();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<table border="1">
		<tr>
			<td valign="top" width="30%">
				<%-- -------- Include menu HTML code -------- --%> <jsp:include
					page="/menu.html" />
			</td>
			<td>Display the roster of class<br>
				<table border="1">
					<tr>
						<th>Course Name</th>
						<th>Section ID</th>
						<th>Title</th>
						<th>Quarter</th>
						<th>Year</th>
						<th>Enroll Limit</th>
					</tr>
					<%=HTML%>
				</table>

			</td>
		</tr>
	</table>
</body>
<%
	// Close the Connection
	conn.close();
%>